/**
 * Created by oudeqi on 2017/6/16.
 */
import Vue from 'vue'
import moment from 'moment'
import { safeDiv, noticeType, noticeStatus } from '@/util'

Vue.filter('date', function(value, format = 'YYYY-MM-DD HH:mm:ss') {
  if (value) {
    return moment(value).format(format)
  } else {
    return '无'
  }
})

Vue.filter('currency', function(value) {
  return '￥' + value.toFixed(2)
})

// 整数分变为代单位的元
Vue.filter('fen2yuan', (val) => {
  if (!val) return '￥0'
  return '￥' + safeDiv(val, 100)
})

Vue.filter('dot', function(val, num = 10) {
  if (val.length <= num) return val
  return val.substring(0, num) + '...'
})

Vue.filter('noticeTypeFilter', function(val) {
  if (val) {
    return noticeType.find((item) => item.value === val).label
  } else {
    return '其他'
  }
})

Vue.filter('noticeStatusFilter', function(val) {
  if (val) {
    return noticeStatus.find((item) => item.value === val).label
  } else {
    return '-'
  }
})
